package com.lagou.code.service.impl;

import com.lagou.code.api.CodeValidationService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.StringUtils;


@Service
public class CodeValidationServiceImpl implements CodeValidationService {

  @Autowired
  private StringRedisTemplate stringRedisTemplate;

  @Override
  public Integer validate(String email, String code) {
    String value = stringRedisTemplate.opsForValue().get(email);
    if (StringUtils.isEmpty(value)) {
      return 1;
    }

    return value.equals(code) ? 0 : 1;
  }
}
